package com.zr.controller.order;

import com.github.pagehelper.PageInfo;
import com.zr.exception.BusinessException;
import com.zr.service.order.OrderFormService;
import com.zr.utils.AjaxResult;
import com.zr.vo.order.OrderForm;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 委托订单处理
 * @author huangguilong
 */
@RestController
@RequestMapping("/order/form")
public class OrderFormController {

    @Resource
    private OrderFormService orderFormService;

    /**
     * 条件查询委托订单列表
     * @param orderForm
     * @return PageInfo<OrderForm>
     * @author huangguilong
     */
    @RequestMapping("/list")
    public AjaxResult list(@RequestBody OrderForm orderForm) {
        PageInfo<OrderForm> pageInfo = orderFormService.list(orderForm);
        return AjaxResult.success(200, "查询成功", pageInfo);
    }

    /**
     * 新增委托订单
     * @param orderForm
     * @return
     * @author huangguilong
     */
    @RequestMapping("/add")
    public AjaxResult add(@RequestBody OrderForm orderForm) throws BusinessException {
        orderFormService.add(orderForm);
        return AjaxResult.success(200, "新增成功", null);
    }

    /**
     * 编辑委托订单
     * @param orderForm
     * @return
     * @author huangguilong
     */
    @RequestMapping("/edit")
    public AjaxResult edit(@RequestBody OrderForm orderForm) {
        orderFormService.edit(orderForm);
        return AjaxResult.success(200, "修改成功", null);
    }

    /**
     * 删除委托订单
     *
     * @param orderForm
     * @return
     * @author huangguilong
     */
    @RequestMapping("/remove")
    public AjaxResult remove(@RequestBody OrderForm orderForm) {
        orderFormService.remove(orderForm);
        return AjaxResult.success(200, "删除成功", null);
    }

    /**
     * 查询状态为已完成的订单
     * @param orderForm
     * @return PageInfo<OrderForm>
     * @author wanglu
     */
    @PostMapping("/getByCustomer")
    public AjaxResult getByCustomer(@RequestBody OrderForm orderForm) {
        return AjaxResult.success(200, "查询成功", orderFormService.getByCustomer(orderForm));
    }

    /**
     * 查询当日新增委托单数量
     * @return int
     * @author 张荣颜
     */
    @PostMapping("/getTodayAddQuantity")
    public int getTodayAddQuantity() {
        return orderFormService.getTodayAddQuantity();
    }

    /**
     * 查询每月订单数量-近一年
     * @return List<OrderForm>
     * @author 张荣颜
     */
    @PostMapping("/getChangeOfOrderQuantityYear")
    public AjaxResult getChangeOfOrderQuantityYear() {
        return AjaxResult.success(200, "查询成功", orderFormService.getChangeOfOrderQuantityYear());
    }

    /**
     * 查询每月订单数量-近半月
     * @return List<OrderForm>
     * @author 张荣颜
     */
    @PostMapping("/getChangeOfOrderQuantitySixMonths")
    public AjaxResult getChangeOfOrderQuantitySixMonths() {
        return AjaxResult.success(200, "查询成功", orderFormService.getChangeOfOrderQuantitySixMonths());
    }

    /**
     * 查询每月订单数量-近一个月
     * @return List<OrderForm>
     * @author 张荣颜
     */
    @PostMapping("/getChangeOfOrderQuantityOneMonth")
    public AjaxResult getChangeOfOrderQuantityOneMonth() {
        return AjaxResult.success(200, "查询成功", orderFormService.getChangeOfOrderQuantityOneMonth());
    }

    /**
     * 查询未完成订单数量
     * @return int
     * @author 张荣颜
     */
    @PostMapping("/getOrderUnfinishedQuantity")
    public int getOrderUnfinishedQuantity() {
        return orderFormService.getOrderUnfinishedQuantity();
    }

    /**
     * 查询各个城市的订单数量与货重
     * @return List<OrderForm
     * @author 张荣颜
     */
    @PostMapping("/getCityOrderWeight")
    public AjaxResult getCityOrderWeight() {
        return AjaxResult.success(200, "查询成功", orderFormService.getCityOrderWeight());
    }

    /**
     * 查询已经结算货款与未结算货款
     * @return List<Map>
     * @author 张荣颜
     */
    @RequestMapping("/getIncomeStatus")
    public AjaxResult getIncomeStatus() {
        List<Map> list = orderFormService.getIncomeStatus();
        return AjaxResult.success(200, "查询", list);
    }

    /**
     * 查询当前调度单未被派发的订单
     * @param id
     * @return List<OrderForm>
     * @author 陈鹏
     */
    @RequestMapping("/listByDispatch/{id}")
    public AjaxResult listByDispatch(@PathVariable("id") Integer id) {
        List<OrderForm> list = orderFormService.listByDispatch(id);
        return AjaxResult.success(200, "查询成功", list);
    }

    /**
     * 获取回单图片
     * @param orderForm
     * @return String
     * @author 陈鹏
     */
    @RequestMapping("/getOrderImg")
    public AjaxResult getOrderImg(@RequestBody OrderForm orderForm) {
        String photo = orderFormService.getImg(orderForm.getFinishImg());
        return AjaxResult.success(200, "查询成功", photo);
    }
}
